#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#include "mpu6050.h"


int main(int argc, char * argv[]){
	
	int fd = -1;
	union mpu6050_data data = {{0}};

	if(argc < 2){
		printf("arg is too few \n");
		return 1;
	}

	fd = open(argv[1], O_RDWR);
	if(fd < 0){
		printf("open failed \n");
		return 2;
	}

	while(1){
		sleep(2);
		ioctl(fd, GET_ACCEL, &data);
		printf("ACCEL X is 0x%x\n", data.accel.x);
		printf("ACCEL Y is 0x%x\n", data.accel.y);
		printf("ACCEL Z is 0x%x\n", data.accel.z);
	
		ioctl(fd, GET_GYRO, &data);
		printf("GYRO X is 0x%x\n", data.gyro.x);
		printf("GYRO Y is 0x%x\n", data.gyro.y);
		printf("GYRO Z is 0x%x\n", data.gyro.z);
		
		ioctl(fd, GET_TEMP, &data);
		printf("TEMP is 0x%x\n", data.temp);
		printf("\n");
	}

	close(fd);
	fd = -1;

	return 0;
}
